package com.dragon.datastructure.tree.avl;

import java.util.ArrayList;
import java.util.List;

/**
 * @author dragon
 * @since 2020/1/3
 */
public class Test {

    public static void main(String[] args) {
        testAdd();
    }

    public static void testAdd() {
        List<String> list = new ArrayList<>();
        AvlTree<String> tree = new AvlTree<>();
        String name = "pride-and-prejudice.txt";
        if (FileOperation.readFile(name, list)) {
            for (String word : list) {
                tree.add(word);
                if (!tree.isBalanced() || !tree.isBinarySearchTree()) {
                    throw new RuntimeException("Error");
                }
            }
        }

        for (String word : list) {
            tree.remove(word);
            if (!tree.isBalanced() || !tree.isBinarySearchTree()) {
                throw new RuntimeException("Error Remove");
            }
        }

    }
}
